//
//  ShangjiaViewController.m
//  MarryMe
//
//  Created by lanou3g on 16/1/6.
//  Copyright © 2016年 revocher. All rights reserved.
//

#import "ShangjiaViewController.h"
#import "ShangjiaTableViewCell.h"
#import "HostModel.h"
#import "NSHandle.h"
#import "DetailViewController.h"
@interface ShangjiaViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *mainTableView;

@end

@implementation ShangjiaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSLog(@"^^^^^^%@",self.cityId);
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(setcity:) name:@"city" object:nil];
    
    self.mainTableView.dataSource = self;
    self.mainTableView.delegate = self;
    NSLog(@"======%@",self.cityId);
    if (!self.cityId) {
        self.cityId = @"1";
    }
    [[NSHandle shareHandle]getNetWorkWithStrUrl:[NSString stringWithFormat:@"http://www.hunliji.com/p/wedding/index.php/home/APIMerchant/getMerchant?per_page=20&property=%@&sort=default&city=%@&page=1",self.property,self.cityId] WithHTTPMethod:nil WithHTTPBody:nil WithBlock:^(BOOL Finished) {
        if (Finished) {
            [self.mainTableView reloadData];
        }
    }];
    
    
    
    
    //cell如果是xib文件,使用以下方式去注册
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ShangjiaTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ShangjiaTableViewCell"];
}

-(void)setcity:(NSNotification *)sender{
    self.cityId = sender.userInfo[@"cityName"];
    NSLog(@"cityId为%@",self.cityId);
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[NSHandle shareHandle].HostArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ShangjiaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShangjiaTableViewCell"];
    HostModel *model = [NSHandle shareHandle].HostArray[indexPath.row];
    [cell setCellWithModel:model];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
    DetailViewController *detailVC = [[DetailViewController alloc]init];
     HostModel *model = [NSHandle shareHandle].HostArray[indexPath.row];
    detailVC.ids = model.ids;
    [self.navigationController pushViewController:detailVC animated:YES];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
